<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>

      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar> -->
    </el-row>

    <!--用户数据-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称">
        <el-input v-model="queryParams.proprietorName" placeholder="请输入名称" maxlength="30" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="queryParams.proprietorType" placeholder="请选择类型" clearable style="width: 240px">
          <el-option v-for="item in dict.type.proprietor_type" :key="item.value" :label="item.label"
                     :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="queryParams.proprietorMobile" placeholder="请输入手机号" v-input.num maxlength="11" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="名称" align="center" key="proprietorName" prop="proprietorName"
                       :show-overflow-tooltip="true"
      />
      <el-table-column label="类型" align="center" prop="createTime">
        <template #default="scope">
          <dict-tag :options="dict.type.proprietor_type" :value="scope.row.proprietorType"/>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="proprietorMobile"/>
      <el-table-column label="创建机构" align="center" prop="createOrganization"/>
      <el-table-column label="房屋委托信息" align="center" prop="houseCommissionStatus">
        <template #default="scope">
          <dict-tag :options="dict.type.house_commission_status" :value="scope.row.houseCommissionStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="代理服务信息" align="center" prop="proxyServiceStatus">
        <template #default="scope">
          <dict-tag :options="dict.type.proxy_service_status" :value="scope.row.proxyServiceStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)" v-hasPermi="['enterprise:proprietor:query']">详情
          </el-button>
          <el-button size="mini" type="text" @click="handleHouseEntrust(scope.row)"
                     v-if="scope.row.houseCommissionStatus != 2"
                     v-hasPermi="['enterprise:commission:add']"
          >房屋委托
          </el-button>
          <el-button size="mini" type="text" @click="handleProxyService(scope.row)"
                     v-if="scope.row.proxyServiceStatus != 3"
          >代理服务
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
    <!--新增弹出层-->
    <Add v-model="open" :title="title" @success="getList" :data="form"/>
    <!--详情弹出层-->
    <Detail v-model="detailOpen" :title="title" :data="form"/>
    <!--房屋委托弹出层-->
    <HouselEntrust v-model="houseEntrustOpen" :title="title" :data="form" @success="getList"/>
    <!--代理服务弹出层-->
    <ProxyService v-model="proxyServiceOpen" :title="title" :data="form" @success="getList"/>
  </div>
</template>

<script>
import Add from '@/views/proprietorInfo/components/add.vue'
import Detail from '@/views/proprietorInfo/components/detail.vue'
import HouselEntrust from '@/views/proprietorInfo/components/house-entrust.vue'
import ProxyService from '@/views/proprietorInfo/components/proxy-service.vue'
import { listCleaner, getCleaner, deleteCleaner } from '@/api/houseCleaning/cleaner.js'

import { listProprietor, getProxyServiceDetail, addProxyService } from '@/api/contract/proprietor'

export default {
  name: 'Index',
  dicts: ['proprietor_type', 'house_commission_status', 'proxy_service_status'],
  components: { Add, Detail, HouselEntrust, ProxyService },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      //业主id
      proprietorId: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proprietorName: undefined,
        proprietorType: undefined,
        proprietorMobile: undefined
      },
      // 详情弹出层
      detailOpen: false,
      // 房屋委托弹出层
      houseEntrustOpen: false,
      // 代理服务弹出层
      proxyServiceOpen: false

    }
  },
  watch: {},
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      listProprietor(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        danhao: undefined,
        fangjian: undefined,
        fenlei: undefined,
        status: undefined,
        yanfangyuan: undefined
      },
        this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.form = undefined
      this.open = true
      this.title = '新增业主'
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.form = row
      this.title = '业主详情'
      this.detailOpen = true
    },
    /** 房屋委托按钮操作 */
    handleHouseEntrust(row) {
      this.form = { ...row }
      this.title = '房屋委托信息'
      this.houseEntrustOpen = true
    },
    /** 代理服务按钮操作 */
    handleProxyService(row) {
      console.log('row', row)
      if (row.proxyServiceStatus == 1) {
        this.$confirm('确认开通分账平台账号和电子签账号？', '提示', {}).then(() => {
          addProxyService({ proprietorId: row.proprietorId }).then(response => {
            this.$message.success(response.msg)
            this.getList()
            this.form = { ...row }
            this.title = '代理服务'
            this.proxyServiceOpen = true
          })
        })
      } else {
        this.form = { ...row }
        this.title = '代理服务'
        this.proxyServiceOpen = true
      }

    }
  }

}
</script>

<style lang="scss" scoped></style>
